import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:localStorage.getItem('token') ? localStorage.getItem('token'):'',   // token
  },
  getters: {
    getStorage(state){   // 获取本地存储的登录信息
      if(!state.token){
        state.token =JSON.parse(localStorage.getItem('token'))
      }
      return state
    }
  },
  mutations: {
    $_setToken(state, value) { // 设置存储token
      state.token = value;
      localStorage.setItem('token', value);
      console.log('token成功')
    },
    $_removeStorage(state){  // 删除token
      state.token=""
      localStorage.removeItem('token');
    },
  },
  actions: {
  },
  modules: {
  }
})
